﻿#pragma strict

var cam:FollowedCamera;
/**移动的速度*/
var moveSpeed:float = 10;
/**xz平面,左下角坐标*/
var leftBottom:Vector3 = Vector3(-3,0,-3);
/**xz平面,右上角坐标*/
var rightUp:Vector3 = Vector3(3,0,3);

function Start () {
	cam = GetComponent.<FollowedCamera>();
	
	//累计移动范围,使其以offsetPos为移动中心点.
	leftBottom += cam.offsetDir;
	rightUp += cam.offsetDir;
}

function Update () {
	MouseMoveCamera();
}

function MouseMoveCamera(){
	var x:float = Input.GetAxis("Mouse X");
	var z:float = Input.GetAxis("Mouse Y");
	
	var dir:Vector3 = Vector3(x,0,z);
		dir *= moveSpeed * Time.deltaTime;
	var offsetPos:Vector3 = cam.offsetDir + dir;
	
	offsetPos.x = Mathf.Clamp(offsetPos.x,leftBottom.x,rightUp.x);
	offsetPos.z = Mathf.Clamp(offsetPos.z,leftBottom.z,rightUp.z);
	
	cam.offsetDir = offsetPos;
}